package com.tuijian.controller;


import com.alibaba.fastjson.JSON;
import com.tuijian.service.recommend.RecommendService;
import com.tuijian.util.RedisUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/recommend")
public class RecommendController {

    @Resource
    private RecommendService recommendService;

    @Resource
    private RedisUtils redisUtils;

    @GetMapping("test")
    public String test(){
        return "test";
    }


    @RequestMapping("/list/{userId}/{type}")
    public String getList(@PathVariable String userId, @PathVariable String type){
        System.out.println("userId:"+userId+","+"type:"+type);

        return JSON.toJSONString(recommendService.getList(userId, type));
    }

    @RequestMapping("/get/{userId}/{type}")
    public List<String> get(@PathVariable String userId, @PathVariable String type){
        System.out.println("userId:"+userId+","+"type:"+type);
        List<String> list1 = new ArrayList<>();
        list1.add("g001");
        list1.add("g002");
        list1.add("g003");
        list1.add("g004");
        list1.add("g005");
        list1.add("g006");
        list1.add("g007");
        list1.add("g008");
        list1.add("g009");
        list1.add("g0010");
        list1.add("g0011");
        list1.add("g0012");
        list1.add("g0013");
        redisUtils.setCacheNewList("post"+userId, list1);
        return redisUtils.getCacheList("post"+userId);
    }



}
